package com.probiz.estoresa.sales.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.sales.Coupon;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.sales.service.CouponManager;
/**
 * 后台优惠券显示controller
 * @author ProBIZ
 *
 */
public class CouponController extends GenericStoreAdminController<Coupon> {
    private CouponManager couponManager = null;

    public void setCouponManager(CouponManager inMgr) {
        this.couponManager = inMgr;
    }

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(Coupon entity) {
		return entity.getCouponName();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = couponManager;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#preSave(javax.servlet.http.HttpServletRequest,
	 *      java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected void preSave(HttpServletRequest request, Coupon entity, BindException errors) {
	}
	
	public ModelAndView search(HttpServletRequest request,
			HttpServletResponse response) {
		SearchCriteria searchCriteria=createSearchCriteria(request);
		String promoRule = request.getParameter("promoRule");
		List results =couponManager.searchCoupons(searchCriteria, promoRule);
		request.setAttribute("promoRule", promoRule);

		return getModelAndView(listView, listModelName, results);
	}

}
